/*
 * @lc app=leetcode.cn id=27 lang=cpp
 *
 * [27] 移除元素
 */

// @lc code=start
#include <vector>
#include <iostream>
using namespace std;
class Solution
{
public:
    int removeElement(vector<int> &nums, int val)
    {
        int temp, count;
        for (size_t i = 0; i < nums.size(); i++)
        {
            if (nums[i] == val)
            {
                for (size_t j = i + 1; j < nums.size(); j++)
                {
                    if (nums[j] != val)
                    {
                        count += 1;
                        temp = nums[i];
                        nums[i] = nums[j];
                        nums[j] = temp;
                        i = j;
                        break;
                    }
                }
            }
        }
        cout << count << endl;
        for (size_t i = 0; i < nums.size(); i++)
        {
            cout << nums[i] << " ";
        }
    }
};
// @lc code=end
